package com.cyw.search.entity.monents;

import cn.easyes.annotation.HighLight;
import cn.easyes.annotation.IndexField;
import cn.easyes.annotation.IndexId;
import cn.easyes.annotation.IndexName;
import cn.easyes.common.constants.Analyzer;
import cn.easyes.common.enums.FieldType;
import cn.easyes.common.enums.IdType;
import cn.easyes.common.params.JoinField;
import com.cyw.common.core.domain.entity.SysUser;
import com.cyw.common.helper.LoginHelper;
import com.cyw.search.vo.CreatorVo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @Author: Chenyw
 * @Date: 2022/11/02/17:09
 */
@Data
@ApiModel("朋友圈文档")
@IndexName(value = "moments_document",shardsNum = 3,replicasNum = 2,childClass = MomentsComment.class)
public class Moments{

    @ApiModelProperty("id")
    @IndexId(type = IdType.NONE)
    private String id;

    @ApiModelProperty("发布者id")
    @IndexField(fieldType = FieldType.LONG)
    private Long userId;

    @ApiModelProperty("发布者")
    @IndexField(fieldType = FieldType.OBJECT)
    private CreatorVo creatorVo;

    @ApiModelProperty("发布者(无用)")
    @IndexField(fieldType = FieldType.NESTED, nestedClass = CreatorVo.class)
    private List<CreatorVo> creatorVos;

    @ApiModelProperty("朋友圈内容")
    @IndexField(fieldType = FieldType.TEXT, analyzer = Analyzer.IK_SMART, searchAnalyzer = Analyzer.IK_MAX_WORD)
    @HighLight(mappingField = "highlightContent")
    private String content;

    @ApiModelProperty("高亮内容")
    private String highlightContent;

    @ApiModelProperty("朋友圈图片")
    @IndexField(fieldType = FieldType.KEYWORD)
    private List<String> imageList;

    @ApiModelProperty("朋友圈点赞量")
    @IndexField(fieldType = FieldType.INTEGER)
    private Integer likeCount = 0;

    @ApiModelProperty("可见形式(0:不可见,1朋友可见,2所有可见)")
    @IndexField(fieldType = FieldType.INTEGER)
    private Integer seeType = 0;

    @ApiModelProperty("朋友圈距离我")
    @IndexField(exist = false)
    private String distance;

    @ApiModelProperty("创建时间")
    @IndexField(fieldType = FieldType.DATE, dateFormat = "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis")
    private String createTime;

    @ApiModelProperty("发布地点经纬度坐标:40.13933715136454,116.63441990026217")
    @IndexField(fieldType = FieldType.GEO_POINT)
    private String location;

    @ApiModelProperty("朋友圈评论")
    @IndexField(fieldType = FieldType.JOIN, parentName = "moments_document", childName = "moments_comment")
    private JoinField joinField;


    public static Moments initPublish(String content,List<String> listUrl,String geoPoint,SysUser sysUser){
        Moments moments = new Moments();
        moments.setContent(content);
        moments.setImageList(listUrl);
        moments.setLocation(geoPoint);
        moments.setUserId(LoginHelper.getUserId());
        CreatorVo creatorVo = new CreatorVo();
        BeanUtils.copyProperties(sysUser,creatorVo);
        moments.setCreatorVo(creatorVo);
        moments.setUserId(sysUser.getUserId());
        moments.setCreateTime(LocalDateTime.now().toString());
        return moments;
    }
}
